package com.example.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

@Component
public class TaskB {

    private DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    //每10秒执行一次
    @Scheduled(cron = "0/10 * *  * * ? ")
    public void test() throws Exception {
        TimeUnit.SECONDS.sleep(20);

        System.out.println("【任务B】每10秒执行一次，当前时间：" + sdf.format(new Date()));
    }
}
